#include "basic_allocator.hpp"
#include <list>
#include <vector>
#include <deque>

using namespace std;
int main(int argc, char** argv)
{
    cout << "==========================\n";
    cout << "allocator on std::list\n";
    {
        list<int, MyAllocator<int>> mylist;
        mylist.emplace_back(42);
        mylist.emplace_back(42);
        mylist.emplace_back(42);
    }
    cout << "==========================\n";
    cout << "==========================\n";
    cout << "allocator on std::vector\n";
    {
        vector<int, MyAllocator<int>> myvec;
        myvec.emplace_back(42);
        myvec.emplace_back(42);
        myvec.emplace_back(42);
    }
    cout
        << R"(if std::vector fills up (that is, runs out of memory), std::vector must
allocate a completely new, contiguous block of memory for all of the elements
in std::vector, copy std::vector from the old memory to the new memory, and
then deallocate the previous block of memory as it is no longer large enough)"
        << '\n';
    cout << "==========================\n";

    cout << "==========================\n";
    cout << "==========================\n";
    cout << "allocator on std::deque\n";
    {
        deque<int, MyAllocator<int>> mydeque;
        for (int k = 0; k < 3; ++k)
            for (int i = 0; i < 127; ++i)
                mydeque.emplace_back(42);
    }
    cout
        << R"(In the preceding example, we add 127 elements three times. This is
because each allocation allocates enough for 128 elements, with one of the
elements being used for bookkeeping. As shown, std::deque allocates three
blocks of memory.)"
        << '\n';
    cout << "==========================\n";
    return 0;
}